package com.icinfo.cloud.provider.punish.ucase.caseregister.enums;

import lombok.Getter;
import org.springframework.util.ObjectUtils;

/**
 * 描述：实名认证果枚举
 *
 * @author shishengyao
 * @description
 * @date 2022/5/17
 */
public enum RealNameCheckResultEnum {

    /**
     * 身份证号校验结果枚举
     */
    CHECK_DIFFERENT("0", "校验不一致"),
    CHECK_SAME("1", "校验一致"),
    CHECK_NO_DATA("3", "未获取到数据"),
    CHECK_FAIL("4", "接口查询失败");

    /**
     * 编码
     */
    @Getter
    private String code;
    /**
     * 描述
     */
    @Getter
    private String des;


    RealNameCheckResultEnum(String code, String des) {
        this.code = code;
        this.des = des;
    }

    /**
     * 描述：根据code获取value
     *
     * @param code 编码
     * @return {@link String }
     * @author shishengyao
     * @date 2022/05/17
     */
    public static String getValueByCode(String code) {
        if (ObjectUtils.isEmpty(code)) {
            return null;
        }
        for (RealNameCheckResultEnum e : RealNameCheckResultEnum.values()) {
            if (code.equals(e.getCode())) {
                return e.getDes();
            }
        }
        return code;
    }

    /**
     * 描述：根据结果查询code
     *
     * @param code 编码
     * @return {@link String }
     * @author shishengyao
     * @date 2022/05/17
     */
    public static String getCodeByCode(String code) {
        if (ObjectUtils.isEmpty(code)) {
            return RealNameCheckResultEnum.CHECK_NO_DATA.getCode();
        }
        return code;
    }

    /**
     * 描述：校验code是否是合法枚举
     *
     * @param code 枚举code
     * @return boolean
     * @author shishengyao
     * @date 2022/05/17
     */
    public static boolean isLegalEnumCode(String code) {
        boolean flag = false;
        for (RealNameCheckResultEnum e : RealNameCheckResultEnum.values()) {
            if (e.getCode().equalsIgnoreCase(code)) {
                flag = true;
                break;
            }
        }
        return flag;
    }
}
